//
//  STOrderVC.m
//  store
//
//  Created by zhouzhouzhou on 2018/9/27.
//  Copyright © 2018年 zhou. All rights reserved.
//

#import "STOrderVC.h"

#import "MLMSegmentManager.h"
//#import "SUNSlideSwitchView.h"
#import "STOrderListView.h"
#import "STOrderDetailVC.h"
#import "STOrderListVC.h"

@interface STOrderVC ()<MLMSegmentScrollDelegate,STOrderListViewDelegate>{
    NSMutableArray * arrVCs;
    NSArray * arrTopBars;
//    SUNSlideSwitchView *slideSwitchView;
    MLMSegmentScroll *segScroll;
    STOrderListView * orderListView;
}

@end

@implementation STOrderVC

- (void)viewDidLoad {
    [super viewDidLoad];
    arrTopBars =@[@"待确认", @"待销核", @"已完成", @"已退款"];
    self.navigationItem.title = @"我的订单";
    [self wr_setNavBarTintColor:[UIColor blackColor]];
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
//    [self drawSubCategoryList];
//    [self loadOrderData];
    
    MLMSegmentHead *segHead = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 40) titles:arrTopBars headStyle:SegmentHeadStyleLine layoutStyle:MLMSegmentLayoutDefault];
    segHead.fontSize = 15;
    segHead.headColor = [UIColor whiteColor];
    segHead.selectColor = UIColorFromRGB(0xF46B45);
    segHead.deSelectColor = UIColorFromRGB(0x333333);
    segHead.bottomLineHeight = 0.0;
    segHead.lineColor = UIColorFromRGB(0xF46B45);
    segHead.lineHeight = 2.0;
    segHead.lineScale = .5;
    
    segScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, 64+40, SCREEN_WIDTH, SCREEN_HEIGHT-40-64) vcOrViews:[self getArrViewWithCount:arrTopBars.count]];
    segScroll.segDelegate = self;
    segScroll.showIndex = self.selType;
    
    [MLMSegmentManager associateHead:segHead withScroll:segScroll completion:^{
        [self.view addSubview:segHead];
        [self.view addSubview:segScroll];
    }];
    
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    [segScroll setContentOffset:CGPointMake(self.selType*segScroll.width, 0) animated:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


//滑动结束
- (void)scrollEndIndex:(NSInteger)index{
    [self orderListScrollTypeChange:index];
}

- (void)animationEndIndex:(NSInteger)index {
    [self orderListScrollTypeChange:index];
}

-(void)orderListScrollTypeChange:(NSInteger)type{
    self.selType = type;
    
}

//加载数据
-(void)loadOrderData{
//    [self loadOrderView];
}

-(NSArray *)getArrViewWithCount:(NSInteger)count{
    NSMutableArray * arr = [NSMutableArray arrayWithCapacity:count];
    for (int i = 0; i<count; i++) {
        STOrderListVC * listVC = [[STOrderListVC alloc] initWithType:i];
        listVC.view.frame =CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-40-64);
        listVC.fatherController = self;
        [arr addObject:listVC];
    }
    return  arr;
}




@end



//- (void)drawSubCategoryList {
//    if (slideSwitchView) {
//        [slideSwitchView removeFromSuperview];
//    }
//
//    slideSwitchView = [[SUNSlideSwitchView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)];
//    [self.view addSubview:slideSwitchView];
//    [slideSwitchView.titleArray removeAllObjects];
//
//    slideSwitchView.tabItemNormalColor = RGBCOLOR(0, 0, 0);
//    slideSwitchView.tabItemSelectedColor = [UIColor orangeColor];
//    slideSwitchView.shadowImage = [UIImage imageNamed:@"sliderShadowImg"];
//    slideSwitchView.slideSwitchViewDelegate = self;
//    slideSwitchView.titleArray = (NSMutableArray *)arrTopBars;
//    slideSwitchView.backgroundColor = [UIColor whiteColor];
//    [slideSwitchView buildUI];
//
//}
//
//- (NSUInteger)numberOfTab:(SUNSlideSwitchView *)view {
//    return arrTopBars.count;
//}
//
//- (UIViewController *)slideSwitchView:(SUNSlideSwitchView *)view viewOfTab:(NSUInteger)number {
//    return self;
//}
//
//- (void)slideSwitchView:(SUNSlideSwitchView *)view didselectTab:(NSUInteger)number {
//
//    if (number%2) {
//        orderListView.orderListArr = @[@"",@"",@""];
//    }else{
//        orderListView.orderListArr = @[@"",@"",@"",@""];
//    }
//    self.selType = number;
//    [orderListView setOrderListView];
//}
